<?php
/**
 * Admin person controller
 *
 * @category    IPB_CMS
 * @package     Application_Module_Admin
 * @subpackage  Controller
 * @copyright   Copyright (c) 2009 IPB CMS <http://ipb-cms.googlecode.com/>
 * @license     http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License
 * @author      Henrique Moody <henriquemoody@gmail.com>
 */
class Admin_PersonController extends Zend_Controller_Action
{

    /**
     * Index action
     *
     * @return void
     */
    public function indexAction()
    {
        $this->_forward('list');
    }

    /**
     * List action
     *
     * Displays a list of people
     *
     * @return void
     */
    public function listAction()
    {
        $adapter = Zend_Db_Table_Abstract::getDefaultAdapter();
        $select  = $adapter->select();
        $select->from('person')->order('personId DESC')->where('personId != 1');
        $paginator = Zend_Paginator::factory($select);
        $paginator->setCurrentPageNumber($this->_getParam('page', 1));

        $this->view->pageTitle('User\'s list');
        $this->view->paginator = $paginator;
    }

    /**
     * Add action
     *
     * Displays a form for registration of people
     * and records the people's information in the database
     *
     * @return void
     */
    public function addAction()
    {
        $request = $this->getRequest();
        $form = new Admin_Form_Person();
        if($request->isPost()) {
            if ($form->isValid($request->getPost())) {
                $model = new Model_Person($form->getValues());
                $model->getDao()->createPerson($model);
                $this->_helper->redirector->gotoUrl('/admin/person');
            }
        }
        $this->view->pageTitle('Creating a new user');
        $this->view->form = $form;
        return $this->renderScript('common/form.phtml');
    }

}
